#ifndef __LIB_MD5__H__
#define __LIB_MD5__H__

#include "libutilsbase.h"

LIB_NS_BEGIN

class LIBAPI TMD5Sum
{	
public:
	TMD5Sum();

	TMD5Sum(const char* sum);
	void Put(const char* buf, unsigned int size);
	std::string ToString();

public:
	static std::string GetStringMD5(const char* pBuff,int Bufflen);
	static std::string GetFileMD5(const TCHAR *  lpFile);	

public:
	bool operator==(const TMD5Sum& sum);

private:
	std::string ToTempString();
	static std::string ConvertoString(const unsigned char* md5);

private:
	unsigned long m_state[4];
	unsigned long m_count[2];
	unsigned char m_buf[64];
	unsigned int  m_bpos;
	bool          m_committed;
	unsigned char m_md5[16];

	void init();
	void update();
	void commit();
	bool isCommitted() const;
};

LIB_NS_END

#endif // MD5SUM__H__